import React, { Component } from 'react'
import Child1 from './Child1'
import { CounterContext } from './Context'

// #2 祖先通过 CounterContext.Provider 配合 value 提供数据
export default class App extends Component {
  state = {
    count: 8,
  }
  changeCount = (num) => {
    this.setState({ count: this.state.count + num })
  }
  render() {
    return (
      <CounterContext.Provider
        value={{
          count: this.state.count,
          changeCount: this.changeCount,
        }}
      >
        <div>
          App
          <hr />
          <Child1 />
        </div>
      </CounterContext.Provider>
    )
  }
}
